package DEEPERsource.DEEPERsource.source.corpus;

import java.util.ListIterator;

import javax.naming.OperationNotSupportedException;

public class CorpusBuilder {
	Text corpus;
	
	public Text initCorpus(String id){
		corpus = new Corpus(id);
		return corpus;
	}
	
	public Text initAbstract(String id, String origId){
		corpus = new Abstract(id, origId);
		return corpus;
	}
	
	public Text addAbstract(String id, String origId){
		Text abstr = null;
		try {
			abstr = new Abstract(id, origId);
			corpus.add(abstr);
		} catch (OperationNotSupportedException e) {
			e.printStackTrace();
		}
		return corpus;
	}
	
	public Text addSentence(String sentence, String id, String origId, String abstId){
		Sentence sent = null;
		ListIterator<Text> i = corpus.iterator();
		while(i.hasNext()){
			Text t = i.next();
			if(t.id().equals(abstId)){
				try {
					sent = new Sentence(sentence, id, origId); 
					t.add(sent);
				} catch (OperationNotSupportedException e) {
					e.printStackTrace();
				}
				break;
			}
		}
		return sent;
	}
	
	public Text getCorpus(){
		return corpus;
	}
}
